<template>
	<view class="page">
		<!-- Header -->
		<view class="headerBag">
			<view class="header-content">
				<image src="/static/icon-Get-into@3.png" class="back" @click="goBack"></image>
				<text class="font18 pagetitle">{{ pageTitle }}</text>
			</view>
		</view>

		<!-- Content -->
		<view class="wrapper">
			<view class="content-container">
				<web-view :src="agreementUrl" class="webview"></web-view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		const config = getApp().globalData.config || {}
		const apiBaseUrl = config.API_BASE_URL || 'https://weixin.youpin91.com.cn'
		return {
			pageTitle: '',
			agreementUrl: '',
			baseUrl: apiBaseUrl
		}
	},

	onLoad(options) {
		console.log('===tag==',options.tag)
		//后续优化
		this.initAgreement(options.tag);
	},

	methods: {
		initAgreement() {
			// 获取用户信息
			const userInfo = uni.getStorageSync('user_info');

			// 注册页面的协议处理
			if (!userInfo || Object.keys(userInfo).length === 0) {
				this.pageTitle = '注册协议';
				uni.setNavigationBarTitle({
					title: '注册协议'
				});
				this.agreementUrl = `${this.baseUrl}home/static_html/register_agreement`;
				console.log('看一下serverAddress：' + this.baseUrl)
				console.log('看一下agreementUrl：' + this.agreementUrl)

				return;
			}

			// 获取当前标签
			const currentTag = uni.getStorageSync('current_tag');
			uni.removeStorageSync('current_tag');

			// 商家协议的处理
			if (currentTag === 'sj_xy') {
				this.pageTitle = '生活商家协议';
				uni.setNavigationBarTitle({
					title: '生活商家协议'
				});
				this.agreementUrl = `${this.baseUrl}home/static_html/merchant_greement`;
				return;
			}

			// 申请合伙人协议处理
			if (currentTag === 'hhr_xy') {
				this.pageTitle = '优享优品平台合伙人协议';
				uni.setNavigationBarTitle({
					title: '优享优品平台合伙人协议'
				});
				this.agreementUrl = `${this.baseUrl}home/static_html/partner_greement`;
				return;
			}

			// 申请市代理协议处理
			if (currentTag === 'sdl_xy') {
				this.pageTitle = '优享优品平台市运营协议';
				uni.setNavigationBarTitle({
					title: '优享优品平台市运营协议'
				});
				this.agreementUrl = `${this.baseUrl}home/static_html/agent_greement`;
				return;
			}

			// 申请云主协议处理
			if (currentTag === 'yg_xy') {
				this.pageTitle = '优享优品平台云主协议';
				uni.setNavigationBarTitle({
					title: '优享优品平台云主协议'
				});
				this.agreementUrl = `${this.baseUrl}home/static_html/staff_greement`;
				return;
			}
		},

		goBack() {
			uni.navigateBack();
		}
	}
}
</script>

<style scoped>
.page {
	height: 100vh;
	display: flex;
	flex-direction: column;
	padding: 0 20rpx;
}

.headerBag {
	display: flex;
	align-items: center;
	padding: 20rpx 30rpx;
	background-color: #fff;
	border-bottom: 1rpx solid #eee;
	position: relative;
}

.header-content {
	display: flex;
	align-items: center;
	width: 100%;
	position: relative;
}

.back {
	width: 40rpx;
	height: 40rpx;
	position: absolute;
	left: 0;
}

.pagetitle {
	flex: 1;
	text-align: center;
	font-size: 36rpx;
	font-weight: 500;
}

.font18 {
	font-size: 36rpx;
}

.wrapper {
	flex: 1;
	overflow: hidden;
}

.content-container {
	height: 100%;
}

.webview {
	width: 100%;
	height: 100%;
}
</style>